// 引入mongoose第三方模块
const mongoose = require('mongoose');
const config = require('config');
// 连接数据库
// 解决报错：(node:14887) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead，增加下一句
mongoose.set('useCreateIndex', true);
mongoose.connect(`mongodb://${config.get("db.user")}:${config.get("db.pwd")}@${config.get("db.host")}:${config.get("db.port")}/${config.get("db.name")}`, { useNewUrlParser: true, useUnifiedTopology: true })
        .then(()=>{console.log('数据库连接成功')})
        .catch(()=>{console.log('数据库连接失败')})